package com.yxx.business.service.impl;

import java.util.List;

import com.yxx.common.annotation.DataScope;
import com.yxx.common.utils.DateUtils;
import com.yxx.common.core.domain.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import com.yxx.common.core.service.impl.ServiceImplPlus;
import com.yxx.business.mapper.TbProjectEngineeringMapper;
import com.yxx.business.entity.TbProjectEngineeringDo;
import com.yxx.business.entity.TbProjectEngineeringVo;
import com.yxx.business.entity.TbProjectEngineeringQueryDto;
import com.yxx.business.entity.TbProjectEngineeringEditDto;
import com.yxx.business.service.ITbProjectEngineeringService;

/**
 * 项目-工程关联Service业务层处理
 *
 * @author yxx
 * @date 2025-08-03
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy, @Autowired})
public class TbProjectEngineeringServiceImpl extends ServiceImplPlus<TbProjectEngineeringMapper, TbProjectEngineeringDo> implements ITbProjectEngineeringService {

    private final TbProjectEngineeringMapper tbProjectEngineeringMapper;

    /**
     * 查询项目-工程关联分页结果
     *
     * @param tbProjectEngineeringQueryDto 项目-工程关联查询实体
     * @return 项目-工程关联分页
     */
    @Override
    public PageResult<TbProjectEngineeringVo> selectTbProjectEngineeringVoPage(TbProjectEngineeringQueryDto tbProjectEngineeringQueryDto) {
        startPage();
        PageResult<TbProjectEngineeringVo> page
                = super.getMyBatisPageResult(selectTbProjectEngineeringDoList(tbProjectEngineeringQueryDto), TbProjectEngineeringVo.class);
        clearPage();
        return page;
    }

    /**
     * 查询项目-工程关联Vo列表
     *
     * @param tbProjectEngineeringQueryDto 项目-工程关联查询实体
     * @return 项目-工程关联集合
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<TbProjectEngineeringVo> selectTbProjectEngineeringVoList(TbProjectEngineeringQueryDto tbProjectEngineeringQueryDto) {
        return super.convertList(tbProjectEngineeringMapper.selectTbProjectEngineeringList(tbProjectEngineeringQueryDto), TbProjectEngineeringVo.class);
    }

    /**
     * 查询项目-工程关联Do列表
     *
     * @param tbProjectEngineeringQueryDto 项目-工程关联查询实体
     * @return 项目-工程关联集合
     */
    @Override
    public List<TbProjectEngineeringDo> selectTbProjectEngineeringDoList(TbProjectEngineeringQueryDto tbProjectEngineeringQueryDto) {
        return tbProjectEngineeringMapper.selectTbProjectEngineeringList(tbProjectEngineeringQueryDto);
    }

    /**
     * 查询单个项目-工程关联
     *
     * @param id 项目-工程关联主键
     * @return 项目-工程关联单个
     */
    @Override
    public TbProjectEngineeringVo selectTbProjectEngineeringVoById(Long id) {
        return super.convertBean(tbProjectEngineeringMapper.selectTbProjectEngineeringById(id), TbProjectEngineeringVo.class);
    }

    /**
     * 新增项目-工程关联
     *
     * @param tbProjectEngineeringQueryDto 项目-工程关联编辑实体
     * @return 结果
     */
    @Override
    public int insertTbProjectEngineering(TbProjectEngineeringEditDto tbProjectEngineeringQueryDto) {
        tbProjectEngineeringQueryDto.setCreateById(getUserIdOrNotLogged());
        tbProjectEngineeringQueryDto.setCreateBy(getUserNameOrNotLogged());
        tbProjectEngineeringQueryDto.setCreateTime(DateUtils.getNowDate());
        return tbProjectEngineeringMapper.insertTbProjectEngineering(super.convertT(tbProjectEngineeringQueryDto));
    }

    /**
     * 修改项目-工程关联
     *
     * @param id 项目-工程关联主键
     * @param tbProjectEngineeringQueryDto 项目-工程关联编辑实体
     * @return 结果
     */
    @Override
    public int updateTbProjectEngineering(Long id, TbProjectEngineeringEditDto tbProjectEngineeringQueryDto) {
        tbProjectEngineeringQueryDto.setUpdateBy(getUserNameOrNotLogged());
        tbProjectEngineeringQueryDto.setUpdateTime(DateUtils.getNowDate());
        return tbProjectEngineeringMapper.updateTbProjectEngineering(super.convertT(tbProjectEngineeringQueryDto).setId(id));
    }

    /**
     * 批量删除项目-工程关联
     *
     * @param ids 需要删除的项目-工程关联主键集合
     * @return 结果
     */
    @Override
    public int deleteTbProjectEngineeringByIds(List<Long> ids) {
        return tbProjectEngineeringMapper.deleteTbProjectEngineeringByIds(ids);
    }

    /**
     * 删除单个项目-工程关联信息
     *
     * @param id 项目-工程关联主键
     * @return 结果
     */
    @Override
    public int deleteTbProjectEngineeringById(Long id) {
        return tbProjectEngineeringMapper.deleteTbProjectEngineeringById(id);
    }
}
